<script>
    function editUser(username) {
        var tts=username=='add'? "新建用户":"编辑‘"+username+"’的信息"
        layer.open({
            type: 2,
            area: ['500px', 'auto'],
            fixed: false, //不固定
            maxmin: true,
            title:tts,
            content: '/userInfo/'+username
        });
    }
    function deleteUser(username){
        $.ajax({
            url: "/deleteUser/"+username,
            data: {username:username},
            type: 'POST',
            dataType: 'json',
            success: function(data){
                layer.msg(data.msg)
                if(data.code==0){
                    location.reload(true)
                }
            }
        })
    }
</script>
<div class="panel panel-default">
    <div class="panel-heading">
        <p class="panel-title text-center">用户列表
        </p>

    </div>
    <table  class="table table-bordered table-hover">
        <thead>
        <th class="text-center">用户名</th>
        <th class="text-center">权限</th>
        {{if regexp .Body.user.Permissions "ADMIN"}}
        <th class="text-center">操作</th>
        {{end}}
        </thead>
        {{range .Body.data}}
        <tr>
            <td class="text-center">{{.UserName}}</td>
            <td class="text-center">{{permtrans .Permissions}}</td>
            {{if ge (permlevel $.Body.user.Permissions) 4}}
            <td class="text-center">
                {{if not (regexp .Permissions "ADMIN")}}
                <a href="#" onclick="editUser('{{.UserName}}')"><img src="/statics/img/edit.png" style="width: 20px;height: 20px;"/></a>
                <a href="#" onclick="deleteUser('{{.UserName}}')"><img src="/statics/img/delete.png" style="width: 20px;height: 20px;"/></a>
                {{end}}
            </td>
            {{end}}
        </tr>
        {{end}}
    </table>
    {{if regexp $.Body.user.Permissions "ADMIN"}}
    <div class="panel-footer text-right"><a href="#" onclick="editUser('add')">add</a></div>
    {{end}}
</div>
